package com.jdk8.demo.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamTest10 {
    public static void main(String[] args) {
        Student student1 = new Student("zhangsan", 20, 100);
        Student student2 = new Student("lisi", 20, 90);
        Student student3 = new Student("wangwu", 30, 90);
        Student student4 = new Student("zhangsan", 40, 80);

        List<Student> students = Arrays.asList(student1, student2, student3, student4);

        //按照学生的姓名进行排序
/*        Map<String, List<Student>> groupByName = students.stream().collect(Collectors.groupingBy(Student::getName));
        System.out.println(groupByName);*/

        //按照学生的名称进行排序并统计记录数
/*        Map<String, Long> groupByNameNum = students.stream().collect(Collectors.groupingBy(s -> s.getName(), Collectors.counting()));
        System.out.println(groupByNameNum);*/

        //按照学生的名称进行排序并统计平均分
/*        Map<String, Double> groupByNameAvgScore = students.stream().collect(Collectors.groupingBy(Student::getName, Collectors.averagingDouble(Student::getScore)));
        System.out.println(groupByNameAvgScore);*/


        // 分区只能分为两种集合,按照score大于等于90进行分片
//        Map<Boolean, List<Student>> partitionByScore = students.stream().collect(Collectors.partitioningBy(s -> s.getScore() >= 90));
//        System.out.println(partitionByScore);

        // 分区只能分为两种集合,按照score大于等于90进行分片计数
        Map<Boolean, Long> partitionByScoreCount = students.stream().
                collect(Collectors.partitioningBy(s -> s.getScore() >= 90, Collectors.counting()));
        System.out.println(partitionByScoreCount);


    }
}